# ------------------------------------------
# Monit configuration file for ElasticSearch
# ------------------------------------------

check process elasticsearch with pidfile {{ elk_elasticsearch.pid_file }}
  start program = "/etc/init.d/elasticsearch restart" with timeout 60 seconds
  stop program  = "/etc/init.d/elasticsearch stop"
  if cpu > 90% for 15 cycles then alert
  if totalmem > 90% for 15 cycles then alert
  if loadavg(15min) greater than 10 for 50 cycles then alert
  group elasticsearch

{% if elk_monit is defined %}
check host elasticsearch_connection with address 0.0.0.0
  if failed url http://0.0.0.0:{{ elk_elasticsearch.http.port }}/ with timeout 15 seconds then alert
  group elasticsearch

check host elasticsearch_cluster_health with address 0.0.0.0
  if failed url http://0.0.0.0:{{ elk_elasticsearch.http.port }}/_cluster/health
     and content == 'green'
     with timeout 60 seconds
     then alert
     alert {{ elk_monit.notify_email }} with mail-format {
       subject:  [monit] elasticsearch: CLUSTER HEALTH PROBLEM at {{ hostname }}
       message:  [{{ hostname }}] $SERVICE $ACTION
                 {% if elk_monit.http_auth and cloud is defined %}
                 --
                 http://{{ elk_monit.http_auth.username }}:{{ elk_monit.http_auth.password_encoded }}@{{ cloud.public_hostname }}:2812/elasticsearch_cluster_health
                 {% endif %}
     }
  group elasticsearch
{% endif %}
